<template>
  <div>
    <!--顶部空白-->
    <div style="height: 3rem;"></div>
    <h3>抗原检测详细数据</h3>
    <div>
      <van-cell title="姓名" :value="latestDetectionDetail.name" />
      <van-cell title="身份证号" :value="latestDetectionDetail.identity" />
      <van-cell title="手机号" :value="latestDetectionDetail.mobilePhone" />
      <van-cell title="省" :value="latestDetectionDetail.province" />
      <van-cell title="市" :value="latestDetectionDetail.city" />
      <van-cell title="区" :value="latestDetectionDetail.area" />
      <van-cell title="详细地址" :value="latestDetectionDetail.detailAddress" />
      <van-cell title="采样方式" :value="latestDetectionDetail.detectMethod" />
      <van-cell title="采样结果" :value="latestDetectionDetail.detectResult" />
      <van-cell title="上传者" :value="latestDetectionDetail.uploadUserName" />
      <van-cell title="上次更新时间" :value="latestDetectionDetail.updateTime" />
      <van-cell title="点击查看抗原图片" @click="showAntigenPhoto()"/>
    </div>
  </div>
</template>

<script>
import { ImagePreview } from 'vant';
export default {
  name: 'AntigenResultDetail',
  data() {
    return {
      identity: '',
      latestDetectionDetail: {},
      image: ''
    }
  },
  mounted() {
    this.getUserIdentity();
    this.getLatestDetectionDetail();
  },
  methods: {

    getUserIdentity(){
      var userInfo = JSON.parse(localStorage.getItem("userInfo"));
      this.identity = userInfo.identity;
    },

    // 通过身份证号获取个人最新一次抗原检测结果详细数据
    getLatestDetectionDetail(){
      this.$axios(
          {
            method: "post",
            url: "http://localhost:8085/detection/getLatestDetectionDetail",
            data: {
              identity: this.identity
            }
          }
      ).then(res => {
        if (res.data.code === 200) {
          this.latestDetectionDetail = res.data.data;
          this.getAntigenPhoto(this.latestDetectionDetail.photoName);
          this.detectMethodFormat(this.latestDetectionDetail);
          this.detectResultFormat(this.latestDetectionDetail);
        }
      })
    },

    // 获取抗原图片
    getAntigenPhoto(photoName){
      this.image = 'http://localhost:8085/detection/getAntigenPhoto/'+photoName;
    },

    // 抗原图片预加载
    showAntigenPhoto(){
      ImagePreview({
        images: [
            this.image
        ],
        closeable: true
      })
    },

    // 采样方式信息转换
    detectMethodFormat(row) {
      switch (row.detectMethod) {
        case 1:
          row.detectMethod = '鼻腔';
          break;
        case 2:
          row.detectMethod = '鼻咽';
          break;
        case 3:
          row.detectMethod = '口腔';
          break;
      }
    },

    // 采样结果信息转换
    detectResultFormat(row) {
      switch (row.detectResult) {
        case 1:
          row.detectResult = '阳性';
          break;
        case 2:
          row.detectResult = '阴性';
          break;
        case 3:
          row.detectResult = '无效结果';
          break;
      }
    }
  }
}
</script>


